package com.yiqi.lottery.feature.lottery.view.adapter;

import android.widget.TextView;

import butterknife.BindView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yiqi.lottery.R;
import com.yiqi.lottery.common.util.DateTool;
import com.yiqi.lottery.entity.bo.CouprceBo;
import com.yiqi.lottery.entity.bo.HallBo;

import java.text.DecimalFormat;

public class BuyHallAdapter extends BaseQuickAdapter<CouprceBo, BaseViewHolder> {


    public BuyHallAdapter() {
        super(R.layout.item_lottery_buyhall);
    }


    @Override
    protected void convert(BaseViewHolder helper, CouprceBo selectItem) {


        String num = txfloat(selectItem.getPre_num(), selectItem.getShare());
        helper.setText(R.id.tv_lottoery_hall_type, selectItem. getBet_label())
                .setText(R.id.tv_lottoery_hall_name, selectItem.getUser_info() != null ? selectItem.getUser_info().getUsername() : "未知")
                .setText(R.id.tv_lottoery_hall_date, "截至：" + DateTool.TimeStamp2Date(selectItem.getFinish_time()))
                .setText(R.id.tv_lottoery_hall_wanchendu, num + "%")
                .setText(R.id.tv_lottoery_hall_jine, selectItem.getAmount_fee() + "")
                .setText(R.id.tv_lottoery_hall_prize, (selectItem.getAmount_fee() / selectItem.getShare()) + "")
                .setText(R.id.tv_lottoery_hall_state, selectItem.getShare()-selectItem.getPre_num()+"");
    }

    /**
     * TODO 除法运算，保留小数
     *
     * @param a 被除数
     * @param b 除数
     * @return 商
     */
    public static String txfloat(int a, int b) {
        // TODO 自动生成的方法存根

        DecimalFormat df = new DecimalFormat("0.00");//设置保留位数

        return df.format((float) a / b * 100);

    }


}
